<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 网站用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <fieldset class="layui-elem-field">
        <legend>权限管理</legend>
        <div class="layui-field-box">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <button class="layui-btn layuiadmin-btn-useradmin add">添加权限</button>
                </div>
                <div class="layui-card-body">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th>权限名</th>
                            <th>地址</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.power_name}</td>
                                <td>{$vo.power_url}</td>
                                <td width="200px;">
                                    <a href="javascript:;" data-id="{$vo.id}" class="layui-btn layui-btn-sm layui-bg-blue edit"><i class="layui-icon">&#xe642;</i></a>
                                    <a href="javascript:;" data-id="{$vo.id}" class="layui-btn layui-btn-sm layui-bg-red del"><i class="layui-icon">&#xe640;</i></a>
                                </td>
                            </tr>
                            {volist name="vo.erji" id="voo"}
                                <tr >
                                    <td>|--{$voo.power_name}</td>
                                    <td>{$voo.power_url}</td>
                                    <td width="100px;">
                                        <a href="javascript:;" data-id="{$voo.id}" class="layui-btn layui-btn-sm layui-bg-blue edit"><i class="layui-icon">&#xe642;</i></a>
                                        <a href="javascript:;" data-id="{$voo.id}" class="layui-btn layui-btn-sm layui-bg-red del"><i class="layui-icon">&#xe640;</i></a>
                                    </td>
                                </tr>
                            {/volist}
                        {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </fieldset>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var $ = layui.$
                ,form = layui.form
                ,table = layui.table;

        $(".add").click(function (){
            //页面层-自定义
            layer.open({
                type: 2
                ,title: '添加权限'
                ,content: "{:url('Rbac/access_operate')}"
                ,maxmin: true
                ,offset: ['15%', '32%']
                ,area: ['400px', '300px']
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                    //点击确认触发 iframe 内容中的按钮提交
                    var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                    submit.click();
                }
            });
        });

        $(".edit").click(function (){
            var id = $(this).data('id');
            //页面层-自定义
            layer.open({
                type: 2
                ,title: '修改权限'
                ,content: '/Admin/Rbac/access_operate/id/' + id
                ,maxmin: true
                ,offset: ['15%', '32%']
                ,area: ['400px', '300px']
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                    //点击确认触发 iframe 内容中的按钮提交
                    var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-edit");
                    submit.click();
                }
            });
        });

        $(".del").click(function (){
            var id = $(this).data('id');
            layer.confirm('确定删除吗?', {
                offset: ['20%', '32%']
            }, function(index){
                $.post("{:url('Rbac/access_del')}", {id:id}, function (e){
                    if (e == 1){
                        layer.msg('删除成功');
                        setTimeout(function () {
                            location.reload(); //重载表格
                            parent.layer.close(index); //再执行关闭
                        }, 500)
                    }else if (e == 2){
                        layer.msg('下面有子集不能删除');
                    }else{
                        layer.msg('删除失败');
                    }
                });
            });

        });
    });

</script>
</body>
</html>
